﻿using Microsoft.AspNetCore.Mvc.ApplicationModels;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace JESAI.DynamicWebApi.Configurations
{
    /// <summary>
    /// 动态WebApi控制器配置类
    /// </summary>
    public class DynamicWebApiControllerAssemblySetting
    {
        /// <summary>
        /// 程序集，动态WebApi所在程序集，作为判断当前程序集归属用
        /// </summary>
        public Assembly Assembly { get; }
        /// <summary>
        /// 控制器Model
        /// </summary>
        public Action<ControllerModel> ControllerModelConfigurer { get; set; }
        /// <summary>
        /// Http谓词（POST/PUT/GET/DELETE···）
        /// </summary>
        public bool UseConventionalHttpVerbs { get; }
        /// <summary>
        /// 模块名称，比如api/{module}/｛controller｝/｛action｝/{id}
        /// </summary>
        public string ModuleName { get; }
        /// <summary>
        /// 类型谓词，判断当前类型是否是控制器，默认配置是true，当设置为false的时候，该程序集不起作用。
        /// </summary>
        public Func<Type, bool> TypePredicate { get; set; }
        public DynamicWebApiControllerAssemblySetting(string moduleName,Assembly assembly, bool useConventionalHttpVerbs)
        {
            ModuleName = moduleName;
            Assembly = assembly;
            TypePredicate = type => true;
            UseConventionalHttpVerbs = useConventionalHttpVerbs;
            ControllerModelConfigurer = controller => { };
        }
    }
}
